import json,xlwt
import os
def readExcel(file):
    with open(file,'r',encoding='utf8') as fr:
        data = json.load(fr) # 用json中的load方法，将json串转换成字典
    return data
def writeM():
    book = xlwt.Workbook() # 创建一个excel对象
    sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页

    fn = os.listdir('/Users/apple/Desktop/9999')
    H = 2
    for it in fn:
        print(it)
        #a = []
        if it.find('json') != -1:
            a = readExcel('9999/'+it)
        #if H != 51:
           
        
        print(a)
    
        if H == 2:
            J = 0
            for i in a: # 循环列
                print(i)
                sheet.write(1,J,i) # 将title数组中的字段写入到0行i列中
                J = J + 1

        I = 0
        for line in a: #　循环字典
            sheet.write(H,I,a[line])  
           
            I = I + 1

        H = H + 1   
        print(H) 
    book.save('demo1.xls')

if __name__ == '__main__':
    writeM()